import sys
from Bio import SeqIO
import random

comp = { 'a' : 't',
		 't' : 'a',					
		 'c' : 'g',
		 'g' : 'c' }

def revcomp(seq):
	return ''.join(comp[nt] for nt in reversed(seq))

if __name__ == '__main__':
	if len(sys.argv) != 2:
		print "usage: %s fasta_file" % sys.argv[0]
		exit()
	def pf(seq):		
		LINE_LENGTH = 80
		for i in range(1+len(seq)/LINE_LENGTH):			
			slc = seq[i*LINE_LENGTH:(i+1)*LINE_LENGTH]
			if slc:
				print slc
	
	#for seq_record in SeqIO.parse(sys.argv[1], "fasta"):
	header = ''
	seqstring = ''
	def dumpseq(seq, hdr):
		parts = []
		
		start = -1
		for i in xrange(len(seq)):
			if seq[i] in ['a','c','t','g'] and start == -1:
				start = i
			elif (seq[i] not in ['a','c','t','g'] or i == len(seq)-1) and start != -1:
				parts.append([start,i + 1 if i == len(seq)-1 else i])
				start = -1
		for part in parts:
			print "%s __PART__:%d-%d" % (hdr, part[0],part[1])
			pf(seq[part[0]:part[1]])
			print "%s __PART__:%d-%d __REVERSE_COMPLEMENT__" % (hdr, part[0],part[1])
			pf(revcomp(seq[part[0]:part[1]]))
		

		
	for line in open(sys.argv[1], "r"):
		if line[0] == '>':
			if header != '':
				dumpseq(seqstring,header)
			header = line.strip()
			seqstring = ''
		else:
			seqstring += line.strip().lower()
		
	if header != '':
		dumpseq(seqstring,header)
			
